package task4;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StudentSystem {
    private List<Student> students;

    public StudentSystem(List<Student> students) {
        setStudents(students);
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    @Override
    public String toString() {
        return students.toString();
    }

    public static void main(String[] args) {
        StudentSystem ss = new StudentSystem(new ArrayList<Student>());
        List<Student> students = ss.getStudents();

        Scanner scanner = new Scanner(System.in);
//        String[] commands = {"增加", "删除", "修改", "查找", "遍历"};
        while(true){
            System.out.println("请输入命令：增加, 删除, 修改, 查找, 遍历, 退出" );
            String command = scanner.next();
            switch(command){
                case "增加":
                    System.out.println("请输入需要增加的学生信息：学号，姓名，年龄");
                    String id = scanner.next();
                    String name = scanner.next();
                    int age = scanner.nextInt();
                    StudentAdd.add(students, id, name, age);
                    ss.setStudents(students);
                    break;
                case "删除":
                    System.out.println("全部学生信息如下：");
                    System.out.println(students);
                    System.out.println("请输入要删除学生的id");
                    id = scanner.next();
                    StudentDel.delete(students, id);
                    break;
                case "修改":
                    System.out.println("请输入要修改的学生信息：学号，姓名，年龄");
                    id = scanner.next();
                    name = scanner.next();
                    age = scanner.nextInt();
                    StudentMod.modify(students, id, name, age);
                    break;
                case "查找":
                    System.out.println("请输入查找方式：ID， 姓名");
                    String subCommand = scanner.next();
                    if("ID".equals(subCommand)){
                        System.out.println("请输入要查询的ID");
                        StudentSearch.searchById(students, scanner.next());
                    }else if("姓名".equals(subCommand)){
                        System.out.println("请输入要查询的姓名");
                        StudentSearch.searchByName(students, scanner.next());
                    }
                    break;
                case "遍历":
                    System.out.println("全部学生信息如下");
                    StudentLoop.loop(students);
                    break;
                case "退出":
                    return;
                default:
                    System.out.println("输入命令不存在");
                    continue;
            }
        }

    }
}
